package com.taos.example;

import com.taosdata.jdbc.TSDBDriver;

import java.sql.*;
import java.util.Properties;

/**
 * @author PC
 */
public class JniConnectExample {
    public static void main(String[] args) throws SQLException {
        // 连接指定数据库：String jdbcUrl = "jdbc:TAOS://127.0.0.1:6030/dbName?user=root&password=taosdata";
        String jdbcUrl = "jdbc:TAOS://127.0.0.1:6030?user=root&password=taosdata";
        Properties connProps = new Properties();
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
        try (Connection connection = DriverManager.getConnection(jdbcUrl, connProps)) {
            System.out.println("获取连接成功");
            DatabaseMetaData metaData = connection.getMetaData();
            System.out.println("数据库类型：" + metaData.getDatabaseProductName() + "，版本：" + metaData.getDatabaseProductVersion());
        }
    }
}
